<?
/*
 *     v2  clsid integrated
 */
define('PILNAS', 'dat/20070417_INCTRL5_VARIOUS.dat');
//     c klasej
define('DFILE', 'dat/def_VARIOUS_LT.dat');
define('WRITE1', 'dat/write1.dat');


include('cstrings.php');
				
class String_manipulation extends CStrings{  

	const PILNAS = 'dat/20070417_INCTRL5_VARIOUS.dat';
	const DFILE  = 'dat/def_VARIOUS_LT.dat';
	const WRITE1 = 'dat/write1.dat';
	
	public function trimTo($string, $trimTo='|'){
		 $spacepos=strrpos($string, $trimTo);
		 return substr($string, $spacepos+1);
	}
	
	/***
	*  Trim array elements
	*
	*/
	public function array_trim(&$value) 
	{
	    $value = trim($value); 
	}


	/**
	 * 	Finds startup files 
	 * @param $source given file source in array
	 * @param $ii file line 
	 * @return array of block fields	
	 */
	
	function findStartup($source, $ii, $parasite){
		
	
		foreach($source as $ii => $line ){
			if(strpos($line, 'STARTUP KEYS') !== false ){
				//removes 'SEARCH LOCATION: '
				$ii ++;
				
				//goes throught paths
				while(!empty($source[++$ii])){
					$path[$ii] = $this->trimTo($source[$ii], ' ');
					
					$search = array('HKCU', 'HKCR', 'HKLM');
					$replaceWith =  array('HKEY_CURRENT_USER', 'HKEY_CLASSES_ROOT', 'HKEY_LOCAL_MACHINE');
					$path[$ii] = str_replace($search, $replaceWith, $path[$ii]);
					
					$find = substr($path[$ii], 0, -1) . " \"$parasite[1]\""; 
						
					$full_file = $this->prepareFile(PILNAS, 'Values added', 1);
					
					
					//trims white spaces						
					foreach($full_file as &$var)
						$var =trim($var);

					if(in_array($find, $full_file)){
						$fput =   '	' . $find . PHP_EOL;
						
						
						file_put_contents(WRITE1, $fput, FILE_APPEND);
					}
				}
			}
		}
		
		
		if(isset($fput))
			return $find;
	}
	
	/**
	 * 
	 * @param $source file source in 
	 * @param int $ii line
	 * @param string &$paths returns  
	 * 
	 */
	function findRegkeys($source, $ii, $parasite){

		$path = str_replace('\{', ' "{',$parasite[1]);
		
		$branches =  array('HKEY_CURRENT_USER\\', 'HKEY_CLASSES_ROOT\\', 'HKEY_LOCAL_MACHINE\\', 'HKEY_USERS\\');

		foreach($branches as $key => $branch)
			$paths[$key] =   $branch . $path . '"';

		foreach($paths as $path){
			$full_file = $this->prepareFile(PILNAS, 'Values added', 1);
				
			if(in_array($path, $full_file)){						
				$fput =  $path . PHP_EOL;
				file_put_contents(WRITE1, $fput, FILE_APPEND);
			}
		}
		
		$ii++;
		
		if(isset($fput))
			return $path;
	}
	
	
	/**
	 * 	Finds CLSID files 
	 * @param $source given file source in array
	 * @param $ii file line 
	 * @return array of block fields	
	 */
	
	function findCLSID($parasite, $full_file){
			$ii=0;
		foreach($full_file as $line){
			if(strpos($line, $parasite[1]) !== false ){
				$fput[$ii++] = file_put_contents(WRITE1, $line. PHP_EOL, FILE_APPEND);
				return $line; 
			}
		}
		
	}
	
	
	/*
	 * 	Finds files listen in FILE block
	 */
	

	function findFiles($parasite){		
		file_put_contents(WRITE1, $parasite. PHP_EOL, FILE_APPEND);
		return $parasite; 
	}
		
}

//////////// code
//

try {
	
	$file = new String_manipulation();
	

	
	$list = array( 
				'BROWSERHELPOBJECT' => 'BROWSERHELPOBJECT',
				'UNINSTALL' => 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\\',
				'STARUPAPPS' => 1,
				'REGKEYS' => 1,
				'CLSID' => 1,
				'FILE' => ''
	);
	
	file_put_contents(WRITE1, '');
	
	$source = $file->prepareFile(DFILE, '<END PARASITE NOTES>', 1);

	foreach($list as $type => $path){
		file_put_contents(WRITE1, $type. PHP_EOL, FILE_APPEND);
		$blocks[$type] = $file->findBegin($type, $source);
	}


	lg($blocks, 'Block');
	
/*	search($file,$word,&$statsList)

	$this->search($cslid,'',&$statsList);	
	lg(&$statsList);
*/
?>
<iframe width="1200" src="<?=WRITE1?>"  height="700"></iframe>;
<?


}
catch(Exception $e){
    echo $e->getMessage();
    exit();
}
    
?>
